<template>
  <div>
    <div>
      <div class="title" style="margin-top: 0">采集方式</div>
      <div class="row margin-b-15">
        <div class="col flex">
          采集方式:
          <div>{{collectTypeListObj[driverInfo.collectType] || '--'}}</div>
        </div>
      </div>
    </div>
    <div v-if="netPort">
      <div class="title">网口信息</div>
      <div class="row margin-b-15">
        <div class="col flex">
          IP地址:
          <div>{{driverInfo.collectIp || '--'}}</div>
        </div>
        <div class="col flex">
          设备端口:
          <div>{{driverInfo.collectPort || '--'}}</div>
        </div>
      </div>
    </div>

    <div v-if="seriesPort">
      <div class="title" style="margin-top: 0">串口信息</div>
      <div class="row margin-b-15">
        <div class="col flex">串口号:
          <div>{{serialPortListObj[driverInfo.serialPort] || '--'}}</div>
        </div>
        <div class="col flex">波特率:
          <div>{{driverInfo.baudRate || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">数据位长度:
          <div>{{driverInfo.dataBit || '--'}}</div>
        </div>
        <div class="col flex">停止位长度:
          <div>{{driverInfo.stopBit || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">校验方式:
          <div>{{driverInfo.parity || '--'}}</div>
        </div>
        <div class="col flex">流控:
          <div>{{driverInfo.flowControl || '--'}}</div>
        </div>
      </div>
    </div>

    <div v-if="ioPort">
      <div class="title">IO口信息-状态</div>
      <div class="row margin-b-15">
        <div class="col flex">IO口:
          <div>{{driverInfo.workIoCheck || '--'}}</div>
        </div>
        <div class="col flex">触发方式:
          <div>{{triggerModeObj[driverInfo.workIoTrigger] || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">消抖延时(ms):
          <div>{{driverInfo.workIoTime || '--'}}</div>
        </div>
      </div>

      <div class="title">IO口信息-计数</div>
      <div class="row margin-b-15">
        <div class="col flex">IO口:
          <div>{{driverInfo.partCountIoCheck || '--'}}</div>
        </div>
        <div class="col flex">触发方式:
          <div>{{triggerModeObj[driverInfo.partCountIoTrigger] || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">消抖延时(ms):
          <div>{{driverInfo.partCountIoTime || '--'}}</div>
        </div>
      </div>

      <div class="title">IO口信息-报警</div>
      <div class="row margin-b-15">
        <div class="col flex">IO口:
          <div>{{driverInfo.alarmIoCheck || '--'}}</div>
        </div>
        <div class="col flex">触发方式:
          <div>{{triggerModeObj[driverInfo.alarmIoTrigger] || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">消抖延时(ms):
          <div>{{driverInfo.alarmIoTime || '--'}}</div>
        </div>
      </div>
    </div>

    <div v-if="moreKey.length > 0">
      <div class="title">驱动配置</div>

      <div class="row margin-b-15" v-for="(row, index) in moreKey" :key="index">
        <div class="col flex" v-for="(item, colIndex) in row" :key="colIndex">
          {{item.key}}:
          <div>{{item.value || '--'}}</div>
        </div>
      </div>
    </div>

    <div>
      <div class="title">采集配置</div>
      <div class="row margin-b-15">
        <div class="col flex">
          采集周期(ms):
          <div>{{driverInfo.collectCycle || '--'}}</div>
        </div>
        <div class="col flex">
          采集间隔(ms):
          <div>{{driverInfo.collectInterval || '--'}}</div>
        </div>
      </div>

      <div v-if="isEnergy" class="row margin-b-15">
        <div class="col flex">
          上报方式:
          <div>{{repTypeObj[driverInfo.repType] || '--'}}</div>
        </div>
      </div>
    </div>

    <div v-if="isCnc">
      <div class="title">文件传输配置</div>
      <div class="row margin-b-15">
        <div class="col flex">传输地址:
          <div>{{driverInfo.fileIp || '--'}}</div>
        </div>
        <div class="col flex">传输端口:
          <div>{{driverInfo.filePort || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">传输协议:
          <div>{{driverInfo.fileProtocol ? dncProtocolTypesObj[driverInfo.fileProtocol] : '--' || '--'}}</div>
        </div>
        <div class="col flex">用户名:
          <div>{{driverInfo.fileUsername || '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">密码:
          <div>{{driverInfo.filePassword || '--'}}</div>
        </div>
        <div class="col flex">传输根目录:
          <div>{{driverInfo.fileDev || '--'}}</div>
        </div>
      </div>

      <div class="title">在线加工配置</div>
      <div class="row margin-b-15">
        <div class="col flex">采集端口:
          <div>{{driverInfo.dncPort || '--'}}</div>
        </div>
        <div class="col flex">传输协议:
          <div>{{driverInfo.dncProtocol ? dncProtocolTypesObj[driverInfo.dncProtocol] : '--'|| '--'}}</div>
        </div>
      </div>
      <div class="row margin-b-15">
        <div class="col flex">用户名:
          <div>{{driverInfo.dncUsername || '--'}}</div>
        </div>
        <div class="col flex">密码:
          <div>{{driverInfo.dncPassword || '--'}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* eslint-disable */
import _ from 'lodash'
import {
  collectTypeListObj,
  serialPortListObj,
  triggerModeObj,
  repTypeObj,
  dncProtocolTypesObj
} from '../list-components/gateway-dialog/constant'

export default {
  name: 'sub-driver-info-detail',
  props: {
    driverInfo: {
      type: Object,
      default: () => {}
    },
    controllerType: {
      type: String,
      default: ''
    }
  },
  computed: {
    isCnc () {
      return this.controllerType === '0'
    },
    isEnergy () {
      return this.controllerType === '2'
    },
    netPort () {
      return this.driverInfo.collectType + '' === '1'
    },
    seriesPort () {
      return this.driverInfo.collectType + '' === '2'
    },
    ioPort () {
      return this.driverInfo.collectType + '' === '3'
    },
    moreKey () {
      if (this.driverInfo && this.driverInfo.moreKey?.length > 0) {
        return _.chunk(this.driverInfo.moreKey, 2)
      }
      return []
    }
  },
  data () {
    return {
      collectTypeListObj: collectTypeListObj,
      serialPortListObj: serialPortListObj,
      triggerModeObj: triggerModeObj,
      repTypeObj: repTypeObj,
      dncProtocolTypesObj: dncProtocolTypesObj
    }
  }
}
</script>

<style scoped lang="scss">
.title {
  line-height: 1;
  font-size: 16px;
  font-weight: 500;
  color: #5f77fd;
}
</style>
